﻿using ComponentFactory.Krypton.Toolkit;
using StableDiffusionTools.Enums;
using StableDiffusionTools.Themes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StableDiffusionTools.Controls.KryptonHelper
{
    public class KryptonThemeContextMenu : KryptonContextMenu
    {
        public KryptonThemeContextMenu() : base()
        {
            void styleSelected(object s, EventArgs e)
            {
                if (s is KryptonContextMenuItem item)
                {
                    if (item.Tag is Theme mode)
                    {
                        GlobalTheme.LoadTheme(mode);
                    }
                }
            }
            KryptonContextMenuItems styleItems = new KryptonContextMenuItems();

            var styles = EnumUtil.GetValues(Theme.Invalid);
            for (int i = 0; i < styles.Length; i++)
            {
                styleItems.Items.Add(new KryptonContextMenuItem(styles[i].ToString(), styleSelected) { Tag = styles[i] });
            }
            Items.Add(styleItems);
            Opening += (s, e) =>
            {
                Theme activeTheme = GlobalTheme.ActiveTheme;
                for (int i = 0; i < styleItems.Items.Count; i++)
                {
                    KryptonContextMenuItem itm = ((KryptonContextMenuItem)styleItems.Items[i]);
                    if (itm.Tag is Theme mode)
                    {
                        itm.Checked = mode == activeTheme;
                    }
                }
            };
        }
    }
}
